package com.gitee.xiao.ai;

import net.bramp.ffmpeg.FFmpeg;
import net.bramp.ffmpeg.FFmpegExecutor;
import net.bramp.ffmpeg.builder.FFmpegBuilder;
import net.bramp.ffmpeg.probe.FFmpegProbeResult;
import net.bramp.ffmpeg.progress.ProgressListener;

/**
 * @author wang xiao
 * date 2024/7/10
 */
public class RecordService {

    /**
     * 录制RTSP流
     * @param rtspUrl 流地址
     * @param outputFilePath mp4
     */
    public  void recordRtspStream(String rtspUrl, String outputFilePath) {
        // 创建 FFmpegBuilder 实例
        FFmpegBuilder builder = new FFmpegBuilder()
                .setInput(rtspUrl)
                .addOutput(outputFilePath)
                .setFormat("mp4")
                .setVideoCodec("copy")
                .setAudioCodec("copy")
                .done();
        try {
            FFmpeg ffmpeg = new FFmpeg();
            FFmpegExecutor executor = new FFmpegExecutor(ffmpeg);
            executor.createJob(builder).run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
